<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>

<form class="layui-form" id="pageSubmit" method="post">

    <input type="hidden" id="currentPage" name="currentPage">
<#-- 上半部分 - 条件查询 -->
    <fieldset class="layui-elem-field">
        <legend>优惠信息查询</legend>
    </fieldset>
<#-- 上半部分内容区域 -->
    <div class="layui-field-box">
    <#-- 普通查询内容区域 -->
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">优惠名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="disName" autocomplete="off"
                           placeholder="请输入"
                           class="layui-input" value="${params.disName!''}">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">优惠值</label>
                <div class="layui-input-inline">
                    <input type="text" name="disValue1" autocomplete="off"
                           placeholder="区" class="layui-input" value="${params.disValue1!''}">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="disValue2" autocomplete="off"
                           placeholder="间" class="layui-input" value="${params.disValue2!''}">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">优惠类型</label>
            <div class="layui-input-inline">
                <select id="contype" name="conType" lay-filter="contype">
                    <option value="">请选择</option>
                    <option value="满减">满减</option>
                    <option value="立减">立减</option>
                    <option value="折扣">折扣</option>
                    <option value="返现">返现</option>
                    <option value="积分">积分</option>
                    <option value="包邮">包邮</option>
                </select>
            </div>

            <label class="layui-form-label">条件名称</label>
            <div class="layui-input-inline">
                <select id="conno" name="conNo">
                <#--根据优惠类型  从促销类型查找  查出有哪些优惠-->
                    <option value="">请选择</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="Form">立即提交</button>
               <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>

<#-- 下半部分 - 查询结果 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>优惠信息</legend>
</fieldset>
<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="200">
            <col width="150">
            <col width="120">
            <col width="150">
            <col width="100">
            <col width="80">
        </colgroup>
        <thead>
        <tr>
            <th>优惠编号</th>
            <th>优惠名称</th>
            <th>优惠类型</th>
            <th>条件名称</th>
            <th>优惠值</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <#list list as item>
        <tr>
            <td>${item.dis_no!''}</td>
            <td>${item.dis_name!''}</td>
            <td>${item.con_type!''}</td>
            <td>
            ${item.con_name!''}
            </td>
            <td>
            ${item.dis_value!''}
            </td>
            <td>
                <div class="layui-btn-group">
                    <button type="button" value="${item.dis_no!''}"
                            class="layui-btn layui-btn-small detail">
                        <i class="layui-icon">详情</i>
                    </button>
                </div>
            </td>
        </tr>
        </#list>
        </tbody>
    </table>
</div>

<div class="layui-form">
    <span id="form_page"></span>&nbsp;共${page.total}条数据
</div>

<script type="text/javascript" src="/static/layui/layui.js"></script>
<script>
    layui.use(['element', 'form', 'layer', 'jquery', 'laypage', 'laydate'], function () {
        var element = layui.element();
        var form = layui.form();
        var layer = layui.layer;
        var laypage = layui.laypage;
        var $ = layui.jquery;
        var laydate = layui.laydate;

        var pindex = "${page.pageNum}";// 当前页
        var ptotalpages = "${page.pages}";// 总页数
        var pcount = "${page.total}";// 数据总数


        //        优惠类型动态赋值
        var conType = "${params.conType!''}";
        //        条件查询动态赋值
        var conNo = "${params.conNo!''}";
        //带回页面的select参数进行动态赋值
        // 优惠类型动态赋值
        $("#contype").find("option[value ='" + conType + "']").attr("selected", "selected");
if (conType!=""){
    $.ajax({
        url: "/act/selectConNoByConType?conType=" + conType,
        type: "POST",
        success: function (data) {
            $("#conno").find('option').remove();
            for (var i = 0; i < data.length; i++) {
                $("#conno").append("<option value='" + data[i].con_no + "'>" + data[i].con_name + "</option>");
            }
            $("#conno").find("option[value ='" + conNo + "']").attr("selected", "selected");

            // 重新渲染页面
            form.render();
        }
    });
}

        // 条件查询动态赋值
        // 重新渲染页面
        form.render();


        // 分页
        laypage({
            cont: 'form_page', // 页面上的id
            pages: ptotalpages,//总页数
            curr: pindex,//当前页。
            skip: true,
            jump: function (obj, first) {
                $("#currentPage").val(obj.curr);//设置当前页
                //防止无限刷新,
                //只有监听到的页面index 和当前页不一样是才出发分页查询
                if (obj.curr != pindex) {
                    console.log(pindex)
                    $("#pageSubmit").submit();
                } else {
                    $("#currentPage").val(1);
                }
            }
        });

        form.on("select(contype)", function (data) {
            console.log(data.value);
            $.ajax({
                url: "/act/selectConNoByConType?conType=" + data.value,
                type: "POST",
                success: function (data) {
                    $("#conno").find('option').remove();
                    for (var i = 0; i < data.length; i++) {
                        $("#conno").append("<option value='" + data[i].con_no + "'>" + data[i].con_name + "</option>");
                    }

                    // 重新渲染页面
                    form.render();
                }
            });
        });


        // 监听查询提交按钮
        form.on('submit(Form)', function (data) {
            $.ajax({
                url: "/act/manage",  //后台程序地址
                type: "POST",
                data: data.field,  //需要post的数据
                success: function (data) {
                }
            });
        });


//        详情弹出窗
        $(".detail").on("click", function () {
            var id = this.value;
            layer.open({
                title: '优惠信息',
                area: ['450px', '430px'],
                type: 2,
                content: '/act/selectByDisno?disNo='+id
            });
        });

    });
</script>
</body>
</html>